﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using Code.Models;
using Code.BLL;
using QianBuo.Lottery.Web.Commen;
using System.Web.Mvc;

namespace QianBuo.Lottery.Web.Models.User
{
    [Serializable]
    public class UserDetail
    {
        public Guid UserID { get; set; }

        [Required(ErrorMessage="用户名不能为空")]
        [DisplayName("用户名:")]
        public string LoginName
        { get; set; }

        [DisplayName("QQ:")]
        [RegularExpression(@"^\d{5,20}$",ErrorMessage="格式不正确")]
        public string QQ
        { get; set; }
        [Required(ErrorMessage="Email不能为空")]
        [DisplayName("Email:")]
        [RegularExpression(@"^[a-zA-Z0-9]+@[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$",ErrorMessage="格式不正确")]
        public string Email { get; set; }

        [RegularExpression(@"^\d+-?\d+$",ErrorMessage="格式不正确")]
        [DisplayName("电话")]
        public string Tel { get; set; }
        /// <summary>
        /// 开户银行
        /// </summary>
        [Required(ErrorMessage="*")]
        [DisplayName("开户银行:")]
        public int? BankID
        { get; set; }
        /// <summary>
        /// 开户城市
        /// </summary>
        [Required(ErrorMessage="*")]
        [DisplayName("开户城市")]
        [DataType(DataType.Custom,ErrorMessage="请选择开户城市")]
        public int? BankCityID { get; set; }

        /// <summary>
        /// 开户城市所在省份名称
        /// </summary>
        public string BankCityProvinceName { get; set; }
        /// <summary>
        /// 开户城市名称
        /// </summary>
        public string BankCityName { get; set; }
        /// <summary>
        /// 其它支付账号
        /// </summary>
        public string PayAccount { get; set; }

        /// <summary>
        /// 街道名称
        /// </summary>
        public string BankStreetName { get; set; }
        /// <summary>
        /// 开户银行名称
        /// </summary>
        public string BankName { get; set; }
        /// <summary>
        /// 银行卡号
        /// </summary>
        [Required(ErrorMessage="*")]
        public string BankCardNo{ get; set; }

        /// <summary>
        /// 真实姓名
        /// </summary>
        [Required(ErrorMessage = "请输入真实姓名")]
        [DisplayName("真实姓名:")]
        public string Name
        { get; set; }
        /// <summary>
        /// 登录密码
        /// </summary>
        [Required(ErrorMessage = "请输入登录密码")]
        [DisplayName("登录密码:")]
        [DataType(DataType.Password)]
        public string LoginPwd
        { get; set; }
        /// <summary>
        /// 验证码
        /// </summary>
        [Required(ErrorMessage = "请输入验证码")]
        [DisplayName("验证码:")]
        public string CheckCode
        { get; set; }
        public class Detail
        {
            public string QQ
            { get; set; }
            public string Tel { get; set; }
            /// <summary>
            /// 开户银行
            /// </summary>
            public int? BankID
            { get; set; }
            /// <summary>
            /// 开户城市
            /// </summary>
            public int? BankCityID { get; set; }
            /// <summary>
            /// 其它支付账号
            /// </summary>
            public string PayAccount { get; set; }

            /// <summary>
            /// 开户城市所在省份名称
            /// </summary>
            public string BankCityProvinceName { get; set; }
            /// <summary>
            /// 开户城市名称
            /// </summary>
            public string BankCityName { get; set; }
            /// <summary>
            /// 街道名称
            /// </summary>
            public string BankStreetName { get; set; }
            /// <summary>
            /// 开户银行名称
            /// </summary>
            public string BankName { get; set; }
            /// <summary>
            /// 银行卡号
            /// </summary>
            public string BankCardNo
            { get; set; }
            /// <summary>
            /// 真实姓名
            /// </summary>
            public string Name
            { get; set; }
        }
        public Detail OldDetail { get; set; }


        /// <summary>
        /// 是否有锁定
        /// </summary>
        public bool Locked
        { get; set; }

        /// <summary>
        /// 是否保存成功
        /// </summary>
        public bool IsSave { get; set; }

    }

    [Serializable]
    [Comparison("ConfirmLoginPwd", "LoginPwd", ComparerOperator.Equal, ErrorMessage = "*")]
    public class AddUser
    {
        [Required(ErrorMessage = "*")]
        [DisplayName("用户名:")]
        [RegularExpression(@"^[0-9a-zA-Z]{4,10}$", ErrorMessage = "*")]
        public string LoginName { get; set; }
        /// <summary>
        /// 登录密码
        /// </summary>
        [Required(ErrorMessage = "*")]
        [DisplayName("登录密码:")]
        [DataType(DataType.Password)]
        [RegularExpression("^.{6,12}$", ErrorMessage = "*")]
        public string LoginPwd { get; set; }
        /// <summary>
        /// 确认密码
        /// </summary>
        [Required(ErrorMessage = "*")]
        [DisplayName("确认密码:")]
        [DataType(DataType.Password)]
        [RegularExpression("^.{6,12}$", ErrorMessage = "*")]
        [CustomComparison(ComparerDataType.String, "LoginPwd", ComparerOperator.Equal, ErrorMessage = "两次密码不一致")]
        public string ConfirmLoginPwd { get; set; }

        [Range(0, 100)]
        public double? WinMoneyMargin { get; set; }
        [Range(0, 100)]
        public double? BackMoneyRagioMargin { get; set; }


        /// <summary>
        /// 类型
        /// </summary>
        [DisplayName("用户级别:")]
        [Required(ErrorMessage = "*")]
        public UserType Type { get; set; }

        public double? MaxBackMoneyRatio { get; set; }

        //[Required(ErrorMessage="*")]
        //public PlayTypeOptionManage.UserOptionSetItem[] Options { get; set; }
        //public Dictionary<int, KeyValue<string,int?>> Lotterys { get; set; }
        /// <summary>
        /// 所有下级数量
        /// </summary>
        [DisplayName("所有下级数量")]
        [Range(0, int.MaxValue)]
        public int? AllChildCount { get; set; }
        /// <summary>
        /// 是否启用配额设置
        /// </summary>
        public bool EnableAddChildConfig { get; set; }

       
        public bool UseSiteBackMoneyRatio { get; set; }
        public bool UseSiteWinMoney { get; set; }
        public Guid Uid { get; set; }
        public string UserName { get; set; }
        public LotteryTypeType? LotteryID { get; set; }
        public ModelNameValue<LotteryTypeType, string> Lotterys { get; set; }
   
        public Code.BLL.PlayTypeOptionManage.WinMoneyOptionSetItem[] Options { get; set; }

    }

    [Serializable]
    public class TakeMoney_Mod
    {
        [Required(ErrorMessage="*")]
        [RegularExpression(@"^\d+$|^\d+\.\d{1,2}0{0,}$",ErrorMessage="格式不正确")]
        [DisplayName("提款金额:")]
        public double? Money { get; set; }
        [Required(ErrorMessage="*")]
        [DisplayName("提款密码:")]
        public string TakePwd { get; set; }
        [DisplayName("您的留言:")]
        public string Msg { get; set; }
        /// <summary>
        /// 已提款次数
        /// </summary>
        public int TakeMoneyCount { get; set; }
        /// <summary>
        /// 最大提款次数
        /// </summary>
        public int MaxTakeMoneyCount { get; set; }
        /// <summary>
        /// 最小提款金额
        /// </summary>
        public double MinTakeMoney { get; set; }
        /// <summary>
        /// 余额
        /// </summary>
        public double Balance { get; set; }

        [Required(ErrorMessage = "选择收款方式")]
        public BankType? Type { get; set; }

        public List<SelectListItem> Types { get; set; }
    }
    [Serializable]
    public class AllChildModel
    {
        public AllChild_Where Where { get; set; }
        public Guid? UserID { get; set; }
        /// <summary>
        /// 下级
        /// </summary>
        public IEnumerable<AllChild_Mod> Childs { get; set; }
        /// <summary>
        /// 无额用户
        /// </summary>
        public List<User_Comm> NoAccountChilds { get; set; }
        /// <summary>
        /// 当前用户的上级
        /// </summary>
        public IEnumerable<AllParent_Mod> Parents { get; set; }
        public PageInfo PageInfo { get; set; }
        public Guid LoginUserID { get; set; }
        public int ChildsCount { get; set; }
        /// <summary>
        /// 是否对注册时间做升序排列
        /// </summary>
        public bool? OrderByRegestTimeASC { get; set; }
        /// <summary>
        /// 是否对余额做升序排列
        /// </summary>
        public bool? OrderByBalanceASC { get; set; }
    }
    [Serializable]
    public class ChildsModel
    {
        /// <summary>
        /// 当前查看的用户的ID
        /// </summary>
        public Guid? CurrentUid { get; set; }
        /// <summary>
        /// 当前登录的用户的ID
        /// </summary>
        public Guid LoginUserID { get; set; }
        public IEnumerable<AllParent_Mod> MyChilds { get; set; }
        public IEnumerable<AllChild_Mod> Childs { get; set; }
        public AllChild_Where Where { get; set; }
        public int ChildsCount { get; set; }
        public PageInfo PageInfo { get; set; }
    }

    [Serializable]
    public class PlayTypeOptionModel
    {
        public bool UseSiteBackMoneyRatio { get; set; }
        public bool UseSiteWinMoney { get; set; }
        public Guid Uid { get; set; }
        public string UserName { get; set; }
        public bool WinMoneyState { get; set; }
        public LotteryTypeType? LotteryID { get; set; }
        public ModelNameValue<LotteryTypeType, string> Lotterys { get; set; }
        [Required]
        public Code.BLL.PlayTypeOptionManage.WinMoneyOptionSetItem[] Options { get; set; }

        
    }
    [Serializable]
    public class AllChild_Where
    {
        /// <summary>
        /// 用户名
        /// </summary>
        [DisplayName("用户名:")]
        public string ChildName { get; set; }
        /// <summary>
        /// 下级代理
        /// </summary>
        [DisplayName("下级代理:")]
        public string Child { get; set; }
        /// <summary>
        /// 注册时间：从
        /// </summary>
        [DisplayName("注册时间")]
        [DataType(DataType.DateTime)]
        public DateTime? StartTime { get; set; }
        /// <summary>
        /// 注册时间：到
        /// </summary>
        [DisplayName("注册时间")]
        [DataType(DataType.DateTime)]
        public DateTime? EndTime { get; set; }
        /// <summary>
        /// 账户金额：从 
        /// </summary>
        [DisplayName("账户金额")]
        [RegularExpression(@"^\d+$|^\d+.\d{1,2}0{0,}$", ErrorMessage = "格式不正确")]
        public decimal? MinMoney { get; set; }
        /// <summary>
        /// 账户金额：到 
        /// </summary>
        [DisplayName("账户金额")]
        [RegularExpression(@"^\d+$|^\d+.\d{1,2}0{0,}$", ErrorMessage = "格式不正确")]
        public decimal? MaxMoney { get; set; }
        ///// <summary>
        ///// 在线状态
        ///// </summary>
        //[DisplayName("在线状态：")]
        //public UserOnlineState State { get; set; }
        public AllChidl_Where_Type? Type { get; set; }
    }

    public enum AllChidl_Where_Type
    {
        /// <summary>
        /// 在线用户
        /// </summary>
        OnLine,
        /// <summary>
        /// 离线用户
        /// </summary>
        DowLine,
        /// <summary>
        /// 有额用户
        /// </summary>
        Richly,
        /// <summary>
        /// 无额用户
        /// </summary>
        Poor,
        /// <summary>
        /// 今日注册
        /// </summary>
        RegestNow
    }
    [Serializable]
    [Comparison("NewPwd","ConfirmLoginPwd",ComparerOperator.Equal,ErrorMessage="两次密码输入不一致")]
    public class EditPwd
    {
        /// <summary>
        /// 登录密码
        /// </summary>
        [Required(ErrorMessage = "*")]
        [DisplayName("新密码:")]
        [DataType(DataType.Password)]
        [RegularExpression("^.{6,12}$", ErrorMessage = "请输入6-12位的任意字符")]
        public string NewPwd
        { get; set; }
        /// <summary>
        /// 确认密码
        /// </summary>
        [Required(ErrorMessage = "*")]
        [DisplayName("确认密码:")]
        [DataType(DataType.Password)]
        [RegularExpression("^.{6,12}$", ErrorMessage = "*")]
        [CustomComparison(ComparerDataType.String, "NewPwd", ComparerOperator.Equal, ErrorMessage = "两次密码不一致")]
        public string ConfirmLoginPwd
        { get; set; }

        /// <summary>
        /// 用户输入的密钥
        /// </summary>
        [Required(ErrorMessage = "*")]
        [DisplayName("密钥:")]
        public string InputPwdKey { get; set; }

        [DisplayName("Email:")]
        public string Email
        { get; set; }

    }

    public class TakeMoneys
    {
        public TakeMoneys()
        {
            if (where == null)
                where = new TackMoeny_Where();
            if (PageInfo == null)
                PageInfo = new PageInfo();
        }
        public class TackMoeny_Where
        {
            /// <summary>
            /// 提款金额
            /// </summary>
            [DisplayName("提款金额")]
            public double? Money { get; set; }

            /// <summary>
            /// 申请时间
            /// </summary>
            [DisplayName("申请时间")]
            [DataType(DataType.DateTime,ErrorMessage="格式不正确")]
            public DateTime? AddTime_Start { get; set; }

            /// <summary>
            /// 申请时间
            /// </summary>
            [DisplayName("申请时间")]
            [DataType(DataType.DateTime,ErrorMessage="格式不正确")]
            //[CustomComparison(ComparerDataType.Date, "AddTime_Start", ComparerOperator.GreaterThanOrEqual)]
            public DateTime? AddTime_End { get; set; }

            /// <summary>
            /// 处理时间
            /// </summary>
            [DisplayName("处理时间")]
            [DataType(DataType.DateTime,ErrorMessage="格式不正确")]
            public DateTime? DoTime_Start { get; set; }

            /// <summary>
            /// 处理时间
            /// </summary>
            [DisplayName("处理时间")]
            [DataType(DataType.DateTime, ErrorMessage = "格式不正确")]
            //[CustomComparison(ComparerDataType.Date, "DoTime_Start", ComparerOperator.GreaterThanOrEqual)]
            public DateTime? DoTime_End { get; set; }

            /// <summary>
            /// 处理状态
            /// </summary>
            [DisplayName("处理状态")]
            public short? State { get; set; }

            public long? ID { get; set; }
        }
        public TackMoeny_Where where { get; set; }
        public IEnumerable<TackMoneys_Mod> TakeMoneyList { get; set; }
        public IEnumerable<SelectListItem> States { get; set; }
        public PageInfo PageInfo { get; set; }
    }

    [Serializable]
    public class WinMoneyModel
    {
        public bool UseSiteWinMoney { get; set; }
        public bool UseSiteBackMoneyRatio { get; set; }
        public Guid Uid { get; set; }
        public string UserName { get; set; }
        public IList<SelectListItem> Lotterys { get; set; }
        public IList<SelectListItem> Ratios { get; set; }
        public NameValue<string, int> WinModels { get; set; }
        public NameValue<NameValueItem<int, string>, IEnumerable<WinMoneyItem>> WinMoneys { get; set; }
    }

    [Serializable]
    public class WinMoneyItem 
    {
        public int PlayTypeID { get; set; }
        public int WinModelID { get; set; }
        public double WinMoney { get; set; }
        public double BadkMoneyRatio { get; set; }

        public double BackMoneyToWinMoneyRatio { get; set; }
        public double MaxBackMoneyToWinMoney { get; set; }
    }

    [Serializable]
    public class SubWinMoneyMarginModel
    {
        public List<SelectListItem> WinModels { get; set; }
        public List<SelectListItem> Lotters { get; set; }
        [Required(ErrorMessage="*")]
        public LotteryTypeType? Lottery { get; set; }
        [Required(ErrorMessage="*")]
        public int? WinModelID { get; set; }
        public string UserName { get; set; }

        [Required]
        public Guid ID { get; set; }
        [Range(0, 100, ErrorMessage = "0-100之间的数字")]
        public double? BackMoneyRatioMargin { get; set; }
        [Range(0, 100, ErrorMessage = "0-100之间的数字")]
        public double? WinMoneyRatio { get; set; }
    }
    [Serializable]
    public class SetAddChildConfigModel
    {
        public SetAddChildConfigModel()
        {
            Serch = new SerchUser();
        }
        public Guid LoginUid { get; set; }
        public PageInfo PageInfo { get; set; }
        #region json提交数据
        public Guid Uid { get; set; }
        public int OldACCValue { get; set; }
        [Range(0, int.MaxValue, ErrorMessage = "请输入正整数")]
        public int ACCValue { get; set; }
        #endregion

        /// <summary>
        /// 配额设置列表
        /// </summary>
        public List<AddChildConfigModel> UsersConfig { get; set; }

        public SerchUser Serch { get; set; }
        public class SerchUser
        {
            /// <summary>
            /// 要搜索的用户的登录名
            /// </summary>
            public string Name { get; set; }
            /// <summary>
            /// 所有配额所在范围的最大值
            /// </summary>
            public int? MaxCount_AllChild { get; set; }
            /// <summary>
            /// 所有配额所在范围的最小值
            /// </summary>
            public int? MinCount_AllChild { get; set; }
            /// <summary>
            /// 可用配额所在范围的最大值
            /// </summary>
            public int? MaxCount { get; set; }
            /// <summary>
            /// 可用配额所在范围的最小值
            /// </summary>
            public int? MinCount { get; set; }
        }
    }
    [Serializable]
    public class AddChildConfigModel
    { 
        public Guid uid { get; set; }
        /// <summary>
        /// 当前用户名
        /// </summary>
        public string UserName { get; set; }
        /// <summary>
        /// 当前用户类型
        /// </summary>
        public short UserType { get; set; }
        /// <summary>
        /// 所有下级配额
        /// </summary>
        public int AllChildCount { get; set; }
        /// <summary>
        /// 目前所乘所有下级配额
        /// </summary>
        public int NowChildCount { get; set; }
    }
    [Serializable]
    public class MoveMoneyModel
    {
        /// <summary>
        /// 下级用户名
        /// </summary>
        [Required(ErrorMessage="*")]
        public string ChildName { get; set; }
        /// <summary>
        /// 金额
        /// </summary>
        [Required(ErrorMessage="*")]
        [Range(1,double.MaxValue,ErrorMessage=">0")]
        public double? Money { get; set; }
        /// <summary>
        /// 密码
        /// </summary>
        [Required(ErrorMessage="*")]
        public string PassWord { get; set; }
    }
}